/**
 * @projectName interview_-assistant
 * @package org.example.controller
 * @className org.example.controller.CrawlerController
 * @copyright Copyright 2025 Thunisoft, Inc All rights reserved.
 */
package org.example.controller;

import org.example.pojo.entity.Article;
import org.example.result.Result;
import org.example.service.CrawlerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * CrawlerController
 * @description
 * @author admin
 * @date 2025/4/14 10:41
 * @version TODO
 */
@RestController
@RequestMapping("/api/crawler")
public class CrawlerController {

    @Autowired
    private CrawlerService crawlerService;

    @PostMapping("/start")
    public Result<?> startCrawler(
            @RequestParam String keyword,
            @RequestParam(defaultValue = "3") int pages
    ) {
        List<Article> result = crawlerService.crawlArticles(keyword, pages);
        return Result.success(Map.of(
                "status", "success",
                "count", result.size()
        ));
    }
}